package com.happe.foodeasy.winter.conf.parser;

import com.happe.foodeasy.winter.helper.ConfigurationFilesParserHelper;
import org.springframework.stereotype.Component;

import java.util.concurrent.Callable;

/**
 * This class is used to parse Winter's configuration file in properties.
 * Created by wubin on 2016-05-19.
 */
@Component("winterConfParser")
public class WinterConfPropertiesParser extends WinterConfInformationParser {
    /*
  * The default value is winter.conf.properties,
  * can override this default value.
  * */
    private String fileName = "winter.conf.properties";

    private synchronized String getFileName() {
        return fileName;
    }

    @SuppressWarnings("all")
    public synchronized void setFileName(String fileName) {
        this.fileName = fileName;
    }

    @Override
    protected Callable<ConfInformationParseResult> requireTaskCallable() {
        return new WinterConfPropertiesCallable();
    }

    private class WinterConfPropertiesCallable extends PropertiesFileParseTaskCallable<ConfInformationParseResult> {
        @Override
        protected Class<ConfInformationParseResult> retrieveParseResultType() {
            return ConfInformationParseResult.class;
        }

        @Override
        protected String retrieveParseFilePath() {
            return ConfigurationFilesParserHelper.getPathInRootClassPath(getFileName());
        }
    }
}
